//https://www.luogu.com.cn/problem/P1282#ide
// 多米诺骨牌
#include <iostream>
using namespace std;

const int N = 1e3 + 10;
const int M = 1e4 + 10;
const int INF = 0x3f3f3f3f;
int m = 5000;

int a[N];
int n;
int dp[N][M];

int main() 
{
    cin >> n; 
    for (int i = 1; i <= n; i++)
    {
        int x, y; cin >> x >> y;
        a[i] = x - y;
    }

    memset(dp, 0x3f, sizeof dp);
    dp[0][0 + m] = 0;

    for (int i = 1; i <= n; i++)
    {
        for (int j = -m; j <= m; j++)
        {
            dp[i][j + m] = min(dp[i - 1][j - a[i] + m], dp[i - 1][j + a[i] + m] + 1);
        }
    }

    int ret = INF;
    for (int i = 0; i <= m; i++)
    {
        ret = min(dp[n][-i + m], dp[n][i + m]);
        if (ret != INF) break;
    }

    cout << ret << endl;
    return 0;
}